package com.wngbms.shard.learn;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

@Slf4j
@Configuration
public class ResourceLoaderAwareLearn implements ResourceLoaderAware {

    // ApplicationContext
    private ResourceLoader resourceLoader;

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;

//        resourceLoader.  FileUrlResource ClassPathResource UrlResource
        Resource resource = resourceLoader.getResource("file:D:\\Download\\123.txt");
        String filename = resource.getFilename();
        log.info("=====>file:[{}]", filename);

        Resource classRes = resourceLoader.getResource("classpath:application.properties");
        String classFileName = classRes.getFilename();
        log.info("=====>classFileName:[{}]", classFileName);

        Resource webRes = resourceLoader.getResource("http:https://www.baidu.com/index.html");
        String webfile = webRes.getFilename();
        log.info("=====>webfile:[{}]", webfile);

    }
}
